<template>
  <el-container class="member-layout">
    <!-- 侧边栏 -->
    <el-aside width="200px" class="member-aside">
      <div class="logo">
        <h2>实验室管理系统</h2>
      </div>
      <el-menu
        :default-active="activeMenu"
        class="el-menu-vertical"
        background-color="#304156"
        text-color="#fff"
        active-text-color="#409EFF"
        @select="handleMenuSelect"
      >
        <el-menu-item index="/attendance">
          <el-icon><Calendar /></el-icon>
          <span>考勤打卡</span>
        </el-menu-item>
        
        <el-menu-item index="/leave-apply">
          <el-icon><Document /></el-icon>
          <span>请假申请</span>
        </el-menu-item>
        
        <el-menu-item index="/weekly">
          <el-icon><Notebook /></el-icon>
          <span>周报管理</span>
        </el-menu-item>
        
        <el-menu-item index="/profile">
          <el-icon><User /></el-icon>
          <span>个人信息</span>
        </el-menu-item>
      </el-menu>
    </el-aside>

    <!-- 主体内容区 -->
    <el-container>
      <!-- Header -->
      <el-header>
        <div class="header-right">
          <span class="username">{{ username }}</span>
          <el-dropdown>
            <el-icon class="user-icon"><Setting /></el-icon>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="handleChangePassword">修改密码</el-dropdown-item>
                <el-dropdown-item @click="handleLogout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>
      
      <!-- Main Content -->
      <el-main>
        <component :is="currentComponent" />
      </el-main>
    </el-container>

    <!-- 修改密码弹窗 -->
    <el-dialog
      v-model="showPasswordDialog"
      title="修改密码"
      width="30%"
    >
      <el-form :model="passwordForm" label-width="100px">
        <el-form-item label="原密码">
          <el-input v-model="passwordForm.oldPassword" type="password" show-password />
        </el-form-item>
        <el-form-item label="新密码">
          <el-input v-model="passwordForm.newPassword" type="password" show-password />
        </el-form-item>
        <el-form-item label="确认新密码">
          <el-input v-model="passwordForm.confirmPassword" type="password" show-password />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="showPasswordDialog = false">取消</el-button>
          <el-button type="primary" @click="confirmChangePassword">确认</el-button>
        </span>
      </template>
    </el-dialog>
  </el-container>
</template>

<script>
import { ref, computed } from 'vue'
import { Calendar, Document, Notebook, User, Setting } from '@element-plus/icons-vue'
import AttendanceCheck from './AttendanceCheck.vue'
import LeaveApply from './LeaveApply.vue'
import MemberWeekly from './MemberWeekly.vue'
import UserProfile from './UserProfile.vue'

export default {
  name: 'MemberLayout',
  components: {
    Calendar,
    Document,
    Notebook,
    User,
    Setting,
    AttendanceCheck,
    LeaveApply,
    MemberWeekly,
    UserProfile
  },
  setup() {
    const activeMenu = ref('/attendance')
    const username = ref('张三')  // 模拟用户名
    const showPasswordDialog = ref(false)
    const passwordForm = ref({
      oldPassword: '',
      newPassword: '',
      confirmPassword: ''
    })
    
    const currentComponent = computed(() => {
      const components = {
        '/attendance': 'AttendanceCheck',
        '/leave-apply': 'LeaveApply',
        '/weekly': 'MemberWeekly',
        '/profile': 'UserProfile'
      }
      return components[activeMenu.value]
    })

    const handleMenuSelect = (index) => {
      activeMenu.value = index
    }

    const handleChangePassword = () => {
      showPasswordDialog.value = true
    }

    const handleLogout = () => {
      // 模拟退出登录
      ElMessage.success('退出成功')
    }

    const confirmChangePassword = () => {
      // 模拟修改密码
      ElMessage.success('密码修改成功')
      showPasswordDialog.value = false
    }

    return {
      activeMenu,
      currentComponent,
      username,
      showPasswordDialog,
      passwordForm,
      handleMenuSelect,
      handleChangePassword,
      handleLogout,
      confirmChangePassword
    }
  }
}
</script>

<style scoped>
.member-layout {
  height: 100vh;
}

.member-aside {
  background-color: #304156;
  color: #fff;
}

.logo {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #2b2f3a;
}

.logo h2 {
  color: #fff;
  margin: 0;
  font-size: 18px;
}

.el-menu {
  border-right: none;
}

.el-header {
  background-color: #fff;
  border-bottom: 1px solid #e6e6e6;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 20px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.username {
  font-size: 14px;
  color: #606266;
}

.user-icon {
  font-size: 20px;
  color: #606266;
  cursor: pointer;
}

.el-main {
  background-color: #f0f2f5;
  padding: 20px;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
</style>
  